Telegram Group & Telegram Channel
📌 Разбор Python-задачи

Если вы ответил 2 — это ловушка

def func(a, b):
res = a + b

res = func(1, 1)
print(res)


На первый взгляд кажется, что res = 2. Но нет.

➡️ Что происходит

1. Функция func(a, b) складывает a + b и сохраняет в переменную res внутри функции.

2. Но! Функция ничего не возвращает. В Python по умолчанию любая функция без return возвращает None.

3. Следовательно, res = func(1, 1) присваивает None.

4. На экран выводится None.

📎 Пост с задачей

Proglib Academy #буст
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/proglib_academy/2779
Create:
Last Update:

📌 Разбор Python-задачи

Если вы ответил 2 — это ловушка

def func(a, b):
res = a + b

res = func(1, 1)
print(res)


На первый взгляд кажется, что res = 2. Но нет.

➡️ Что происходит

1. Функция func(a, b) складывает a + b и сохраняет в переменную res внутри функции.

2. Но! Функция ничего не возвращает. В Python по умолчанию любая функция без return возвращает None.

3. Следовательно, res = func(1, 1) присваивает None.

4. На экран выводится None.

📎 Пост с задачей

Proglib Academy #буст

BY Proglib.academy | IT-курсы


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/proglib_academy/2779

View MORE
Open in Telegram


Proglib academy | IT курсы Telegram | DID YOU KNOW?

Date: |

To pay the bills, Mr. Durov is issuing investors $1 billion to $1.5 billion of company debt, with the promise of discounted equity if the company eventually goes public, the people briefed on the plans said. He has also announced plans to start selling ads in public Telegram channels as soon as later this year, as well as offering other premium services for businesses and users.

The messaging service and social-media platform owes creditors roughly $700 million by the end of April, according to people briefed on the company’s plans and loan documents viewed by The Wall Street Journal. At the same time, Telegram Group Inc. must cover rising equipment and bandwidth expenses because of its rapid growth, despite going years without attempting to generate revenue.

Proglib academy | IT курсы from ms


Telegram Proglib.academy | IT-курсы
FROM USA